﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TenderSampleApp.Models;
using System.IO;

namespace TenderSampleApp.Controllers
{
    public class LoadVatController : Controller
    {
        DAL dl = new DAL();



        [HttpGet]
        public ActionResult LoadEnterpri()
        {
            return View();
        }
        [HttpPost]
        public ActionResult LoadEnterpri(HttpPostedFileBase file)
        {
            List<VATModel> vatm = null;
            // Verify that the user selected a file
            if (file != null && file.ContentLength > 0)
            {
                // extract only the fielname
                var fileName = Path.GetFileName(file.FileName);
                // store the file inside ~/App_Data/uploads folder
                var path = Path.Combine(Server.MapPath("~/Content/uploads"), fileName);
                file.SaveAs(path);
                //vatm = dl.ReadDBFFileVAT(path);
                Session["listVat"] = vatm;
            }
            // redirect back to the index action to show the form once again

            return RedirectToAction("AddVAT");
        }

        public ActionResult AddVAT()
        {
           List<VATModel>listVat = Session["listVat"] as List<VATModel>;
          
            return View(listVat);
        }

        [HttpPost]
        public ActionResult AddVAT(VATModel vat)
        {
            dl.AddVAT(vat);
            List<VATModel> listVat = Session["listVat"] as List<VATModel>;
            return View(listVat);
        }
        public JsonResult GetRegion(string code)
        {
            return Json(dl.GetRegion(code),JsonRequestBehavior.AllowGet);
        }
      

    }
}
